class Solution(object):
    def exclusiveTime(self, n, logs):
        """
        :type n: int
        :type logs: List[str]
        :rtype: List[int]
        """
        t = [0] * n
        stack = []
        last_time = 0
        for log in logs:
            s = log.split(':')
            s[0] = int(s[0])
            s[2] = int(s[2])
            if s[1] == 'start':
                if stack:
                    t[stack[-1]] += s[2] - last_time
                stack.append(s[0])
                last_time = s[2]
            else:
                last = stack.pop()
                t[last] += s[2] - last_time + 1
                last_time = s[2] + 1
        return t